<template>
  <div style="width: 100%;height: 500px;padding-top:0;margin: 0 ">
    <div class="pageheader">
      <div class="pageheader-1">
        <i class="el-icon-user-solid"></i><label>参合登记</label>
      </div>
      <div style="height: 100%;position: absolute;top: 20px;left: 350px">
        <el-form :model="input" ref="key">
        <el-input
          style="width: 200px;position: absolute;top: 5px;left: 0px"
          size="small"
          placeholder="请输入户主姓名"
          suffix-icon="el-icon-search"
          maxlength="20"
          v-model="input.input3">
        </el-input>
        <el-button type="primary" v-show="list[1].children[1].find" class="searchbtn" @click="find('key')" plain>查询</el-button>
        </el-form>
      </div>
      <el-dialog title="参合登记" @click="this.reload"  :visible.sync="eopencheng">
        <el-form :rules="rules" :model="pepleform" ref="editpeple">
          <el-form-item  prop="chengname" label="姓名" :label-width="formLabelWidth">
            <el-input :disabled="true" v-model="pepleform.chengname" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="sex" label="性别" :label-width="formLabelWidth">
            <el-input :disabled="true" v-model="pepleform.sex" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="age" label="年龄" :label-width="formLabelWidth">
            <el-input :disabled="true" v-model="pepleform.age" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="chengid" label="身份证号" :label-width="formLabelWidth">
            <el-input :disabled="true" v-model="pepleform.chengid" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="nongid" label="农合证号" :label-width="formLabelWidth">
            <el-input :disabled="true" v-model="pepleform.nongid" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="guanxi" label="与户主关系" :label-width="formLabelWidth">
            <el-input :disabled="true" v-model="pepleform.guanxi" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="housts" label="家庭住址" :label-width="formLabelWidth">
            <el-input :disabled="true" v-model="pepleform.housts" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item  prop="canheid" label="参合编号" :label-width="formLabelWidth">
            <el-input  v-model="pepleform.canheid" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="resig" label="参合发票号" :label-width="formLabelWidth">
            <el-input  v-model="pepleform.resig" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="chantime" label="参合时间" :label-width="formLabelWidth">
            <el-input v-model="pepleform.chantime" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="tel" label="联系方式" :label-width="formLabelWidth">
            <el-input :disabled="true" v-model="pepleform.tel" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="eopencheng = false">取 消</el-button>
          <el-button type="primary" @click="editpeple ('editpeple')">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog
        title="提示"
        :visible.sync="openelete"
        width="30%"
        center>
        <span>参合登记成功</span>
        <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="openelete = false" >确 定</el-button>
  </span>
      </el-dialog>
    </div>
    <el-table
      :data="tableData"
      border
      style="width: 100%;height: 80%">
      <el-table-column
        prop="nongid"
        width="100"
        label="农合证号">
      </el-table-column>
      <el-table-column
        prop="chengname"
        width="80"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="chengid"
        label="身份证号">
      </el-table-column>
      <el-table-column
        prop="sex"
        width="55"
        label="性别">
      </el-table-column>
      <el-table-column
        prop="age"
        width="55"
        label="年龄">
      </el-table-column>
      <el-table-column
        prop="guanxi"
        width="110"
        label="与户主关系">
      </el-table-column>
      <el-table-column
        prop="housts"
        label="家庭住址">
      </el-table-column>
      <el-table-column
        prop="tel"
        width="120"
        label="联系方式">
      </el-table-column>
      <el-table-column
        width="100"
        prop="resig"
        label="参合发票">
      </el-table-column>
      <el-table-column
        fixed="right"
        v-show="list[1].children[1].addshow"
        label="操作">
        <template slot-scope="scope">
          <el-button  type="primary" v-show="scope.row.resig === '未参合'"  @click="o_editpeple(scope.row)">参合</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  inject: ['reload', 'list'],
  methods: {
    // 查询功能
    find (key) {
      const _this = this
      if (this.input.input3 !== '') {
        axios.get('http://localhost:8088/findByHuzhu/' + this.input.input3).then(function (resp) {
          _this.tableData = resp.data
          if (resp.data === '') {
            alert('啥也没有找到，请检查是否输入正确')
          }
        })
      } else {
        alert('请输入户主名')
      }
    },
    // 添加
    add (addAction) {
      const _this = this
      this.$refs[addAction].validate((valid) => {
        axios.get('http://localhost:8088/findByAreaidF/' + this.form.areaid).then(function (resp) {
          console.log(resp)
          if (resp.data === '') {
            axios.post('http://localhost:8088/saveArea', _this.form).then(function (resp) {
              _this.$message({
                message: '添加成功！',
                type: 'success'
              })
              _this.reload()
            })
          } else {
            alert('编号已经存在，请重新输入！')
          }
        })
      })
    },
    editpeple (editpeple) {
      this.$refs[editpeple].validate((valid) => {
        axios.post('http://localhost:8088/savePeples', this.pepleform).then(function (resp) {
        })
        axios.post('http://localhost:8088/saveCanhe', this.pepleform).then(function (resp) {
        })
      })
      this.openelete = true
      this.eopencheng = false
    },
    o_editpeple (row) {
      this.pepleform = row
      this.eopencheng = true
    }
  },
  // 接受后台数据
  created () {
  },
  //  数据绑定
  data () {
    return {
      total: null,
      input: {
        input3: ''
      },
      tableData: null,
      eopencheng: false,
      rules: {
        age: [
          { required: true, message: '请输入成员年龄', trigger: 'blur' }
        ],
        chantime: [
          { required: true, message: '请输入参合时间', trigger: 'blur' }
        ],
        chengid: [
          { required: true, message: '请输入身份证号', trigger: 'blur' }
        ],
        chengname: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        guanxi: [
          { required: true, message: '与户主关系不能为空', trigger: 'blur' }
        ],
        housts: [
          { required: true, message: '请填写家庭住址', trigger: 'blur' }
        ],
        nongid: [
          { required: true, message: '农合证号不能为空', trigger: 'blur' }
        ],
        resig: [
          { required: true, message: '请输入参合发票号', trigger: 'blur' }
        ],
        sex: [
          { required: true, message: '请输入性别', trigger: 'blur' }
        ],
        tel: [
          { required: true, message: '请填写联系方式', trigger: 'blur' }
        ],
        canheid: [
          { required: true, message: '参合编号不能为空', trigger: 'blur' }
        ]
      },
      openelete: false,
      pepleform: {
        id: '',
        age: '',
        chantime: '',
        chengid: '',
        chengname: '',
        familyid: '',
        guanxi: '',
        housts: '',
        nongid: '',
        resig: '',
        sex: '',
        tel: '',
        canheid: ''
      },
      formLabelWidth: '100px'
    }
  }
}
</script>
